package com.example.bingobox.data;

import android.content.Context;
import android.widget.Toast;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class StateInitializer implements Initializer {
    private final Gson gson;

    public StateInitializer() {
        this.gson = new GsonBuilder().setPrettyPrinting().create();
    }

    @Override
    public void initialize(Context context, File dataDir) {
        File stateFile = new File(dataDir, "state.json");
        if (!stateFile.exists()) {
            try {
                Map<String, Object> stateData = new HashMap<>();
                
                // 添加默认的地点类型
                List<String> defaultLocationTypes = new ArrayList<>();
                defaultLocationTypes.add("自宅");
                defaultLocationTypes.add("工作单位");
                stateData.put("locationTypes", defaultLocationTypes);
                
                String json = gson.toJson(stateData);
                try (FileWriter writer = new FileWriter(stateFile)) {
                    writer.write(json);
                }
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(context, "创建状态数据文件失败: " + e.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }
    }
} 